{{ partial "header.html" . }}
{{- partial "meta.html" . -}}

<!-- TOC START -->
{{$b := or .Params.show_toc }}
{{ if ($b) }}
<script src="/js/simpletoc.js"></script>
<script>
	var firstLvl = 2; // h1开始
	var lastLvl = 3;  // h3结束
	var divID = "#TOC";
	var divToSearch = "#post";
	window.onload=function(){
		//参数控制
		// 参数一：起始level，默认为h2
		// 参数二：末位Level，默认为h3
		// 参数三：用于生成toc的divID，默认为TOC
		// 参数四：搜索headlines的divID
		var t = toc(
		  firstLvl, lastLvl, divID, divToSearch, 
  		{{if eq .Params.showchapter true }}{{.Params.showchapter}}{{else}}{{false}}{{end}}, 
  		{{if isset .Params "showtoc"}}{{.Params.showtoc}}{{else}}{{true}}{{end}}
		);
		var elToInsert = document.querySelector("#post");
		elToInsert.insertAdjacentElement("beforebegin", t);
	}
</script>
{{ end }}  
<!-- TOC END -->

<div id="post">
  {{- .Content -}}
  
  {{ if .Section }}
  <nav class="post-nav">
    <span class="nav-prev">{{ with .PrevInSection }}&larr; <a href="{{ .RelPermalink }}">{{ .Title }}</a>{{ end }}</span>
    <span class="nav-next">{{ with .NextInSection }}<a href="{{ .RelPermalink }}">{{ .Title }}</a> &rarr;{{ end }}</span>
  </nav>
  <!-- 可以用左右键翻页 START -->
  <script type="text/javascript">
  document.addEventListener('keyup', function(e) {
    if (e.target.nodeName.toUpperCase() != 'BODY') return;
    var url = false;
    if (e.which == 37) {  // Left arrow
      {{ if .PrevInSection }}
      url = '{{ .PrevInSection.RelPermalink }}';
      {{ end }}
    } else if (e.which == 39) {  // Right arrow
      {{ if .NextInSection }}
      url = '{{ .NextInSection.RelPermalink }}';
      {{ end }}
    }
    if (url) window.location = url;
  });
  </script><!-- 可以用左右键翻页 ------------- END -->
  {{ end }}
</div>

<div class="back-to-top"><a href="#">↩</a></div>


<!-- 为rmarkdown的代码输出设置样式 -->
{{- if and (not .Params.disable_highlight) (in (string .Content) "</pre>") -}}
<script>
console.log("start");
(function() {
  var i,nextel,thisIsPre, els = document.querySelectorAll("pre > code");
  if(els) {
    Array.prototype.forEach.call(els, function(item) {
      var check = item.className.includes("language-r") || item.className.includes("language-python");
      if(check) {
        nextel = item.parentElement.nextElementSibling;
        nextelChild = nextel.querySelector("code");
        thisIsPre = nextel.nodeName.toUpperCase() == "PRE";
        console.log("thisispre =  ", thisIsPre);
        // 要设置样式的条件，此时的item为pre下的code
        // 1. item的父标签的下一标签为pre
        // 2. item的父标签的下一标签的子标签为code，并且没有样式
        if(nextelChild == null) return;
        if(thisIsPre && !nextelChild.className.includes("language")) {
          item.parentElement.nextElementSibling.setAttribute("class", "output-code");      
        } // END if
      } // END if
    }); // END Array for each
  }; // END if
  console.log("end");
})();
</script>
{{- end -}}


{{- partial "disqus.html" . -}}

<!-- mathjax START -->
{{ if or (eq .Params.mathjax true) (or (in (string .Content) "\\") (in (string .Content) "$"))}}
<!-- <script src="{{ .Site.BaseURL }}js/mathcode.js"></script> -->
<!-- https://yihui.name/cn/2017/04/mathjax-markdown/ -->
<!-- /js/math-code.js -->
<script src="/js/mathcode2.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
  CommonHTML: {
    scale: 110
  },
  tex2jax: {
    inlineMath: [['$','$'], ['\\(','\\)']],
    processEscapes: true,
    processEnvironments: true,
    skipTags: ['script', 'noscript', 'style', 'textarea', 'pre'],
    TeX: { equationNumbers: { autoNumber: "AMS" },
         extensions: ["AMSmath.js", "AMSsymbols.js"] }
  }
});
</script>
<script async src="https://cdn.bootcss.com/mathjax/2.7.4/MathJax.js?config=TeX-MML-AM_CHTML"></script>
{{ end }}
<!-- mathjax END -->

{{ partial "footer.html" . }}
